package cn.ffcs.bpmpvc.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import org.apache.commons.lang.StringUtils;

import cn.ffcs.base.web.BaseAction;
import cn.ffcs.bpm.model.ProcTranRecord;
import cn.ffcs.bpm.model.TransactProcessStatus;
import cn.ffcs.bpmpvc.graph.Node;
import cn.ffcs.bpmpvc.svc.TaskAssignBean;
import cn.ffcs.bpmpvc.svc.TaskService;
import cn.ffcs.bpmpvc.utils.FlowContextUtil;
import cn.ffcs.bpmpvc.web.views.ProcessInstView;
import cn.ffcs.bpmpvc.web.views.TaskView;
import cn.ffcs.businessrequest.model.ReqDocu;
import cn.ffcs.organ.model.Person;
import cn.ffcs.util.context.ApplicationContextUtil;

public class FlowAppBaseAction <D extends TransactProcessStatus> extends BaseAction<D>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void setStartFlowMsg(boolean isCommit) {
		returnMsg=FlowContextUtil.setStartFlowMsg(isCommit);
	}
	
	
	protected void setCommitTaskMsg(boolean isCommit) {
        returnMsg=FlowContextUtil.setCommitTaskMsg(isCommit);
	}
	
	protected void judgeDocuIsUpload(TaskView taskView, List<ReqDocu> reqDocuList)
    {
		FlowContextUtil.judgeDocuIsUpload(taskView, reqDocuList);
        
    }
	
	protected void setRepDocTableStyleList(List<ReqDocu> list){
		
		FlowContextUtil.setRepDocTableStyleList(list);
	}
	
	protected List<TaskAssignBean> getNextTaskUserList(HttpServletRequest req)
    {
        return FlowContextUtil.getNextTaskUserList(req);
        
    }
	
	protected void setProcessInstTaskInfo(TaskService taskService,ProcessInstView processInstView,String procinstId){
		List<Node> nodeList = taskService.getFlowPvcDao().findRunNodeList(procinstId);
		if (nodeList.size() == 0) {
			Node node = new Node();
			node.setName("结束");
			nodeList.add(node);
		}
		String nowMan="";
		ApplicationContextUtil.getHttpServletRequest().setAttribute("runNodeList", nodeList);
		List<ProcTranRecord> list = processInstView.getFlowTaskList();
		for (int i = 0; i < list.size(); i++) {
			ProcTranRecord procTranRecord = list.get(i);
			if (procTranRecord.getTransactTime() == null&&!("03".equals(procTranRecord.getTaskType()))) {
				Person person = procTranRecord.getTransactor();
				nowMan+=person.getName()+",";
				//ApplicationContextUtil.getHttpServletRequest().setAttribute("nowMan", person.getName());
				//break;
			}
		}
		if(StringUtils.isNotBlank(nowMan)){
			nowMan=nowMan.substring(0,nowMan.length()-1);
		}
		ApplicationContextUtil.getHttpServletRequest().setAttribute("nowMan", nowMan);
	}
	
    protected void writeLabel(WritableSheet sheet,int row,String oneH,String oneC,jxl.write.WritableCellFormat wcfFh,jxl.write.WritableCellFormat wcfFc) throws RowsExceededException, WriteException{    	
    	Label label = new Label(0, row, oneH,wcfFh);
		sheet.addCell(label);
		
		sheet.mergeCells(1, row, 7, row);
		label = new Label(1, row, oneC,wcfFc);
		sheet.addCell(label);
    }
    
    protected void writeLabel(WritableSheet sheet,int row,String oneH,String oneC,String twoH,String twoC,jxl.write.WritableCellFormat wcfFh,jxl.write.WritableCellFormat wcfFc) throws RowsExceededException, WriteException{    	
    	Label label = new Label(0, row, oneH,wcfFh);
		sheet.addCell(label);
		
		sheet.mergeCells(1, row, 3, row);
		label = new Label(1, row, oneC,wcfFc);
		sheet.addCell(label);
		
		
		label = new Label(4, row, twoH,wcfFh);
		sheet.addCell(label);
		
		sheet.mergeCells(5, row, 7, row);
		label = new Label(5, row, twoC,wcfFc);
		sheet.addCell(label);
    }
}
